import java.util.Scanner;

public class PRIME1 {
	// generate primes between 2 numbers
	// http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
	// sieve method : remove prime multiplier by jumping number size..2-?4,6,8
	// 3->6,9 etc.
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int MAX = 1000000000;
		int SIZE = (int) Math.sqrt(MAX) + 1;
		boolean[] primes = new boolean[SIZE];

		primes[0] = true;
		primes[1] = true;

		for (int i = 2; i < SIZE; i++) {
			if (!primes[i]) {
				for (int j = 2; i * j < SIZE; j++) {
					primes[i * j] = true;
				}
			}
		}

		// the false one are primes
		// for (int i = 0; i < primes.length; i++) {
		// if(!primes[i]) {
		// System.out.println(i + "=" + primes[i]);
		// }
		// }

		int t = s.nextInt();
		while (t-- > 0) {
			int x = s.nextInt();
			int y = s.nextInt();

			// for (int i = x; i <= y; i++) {
			// boolean isPrime = (i != 1);// true if its not 1
			// for (int j = 2; j * j <= i; j++) {
			// if (!primes[j]) {// its a prime0
			// if (i % j == 0) {
			// isPrime = false;
			// break;
			// }
			// }
			// }
			// if (isPrime) {
			// System.out.println(i);
			// }
			// }
			// System.out.println("break..");

			// sol2
			boolean numbers[] = new boolean[y - x + 1];

			// special 1
			if (x == 1) {
				numbers[0] = true;
			}

			int sqrt = (int) Math.sqrt(y);
			for (int i = 2; i <= sqrt; i++) {
				if (!primes[i]) { // if prime
					// System.out.println("i=" + i);

					// get first divisible number >= x
					int start = x / i;
					if (x % i == 0) {
						start = x;
					} else {
						start = (start * i) + i;
					}

					// System.out.println("start=" + start);
					for (int j = start; j <= y; j = j + i) {
						// System.out.println(j);
						if (j != i) { // except itself
							// System.out.println("j=" + j);
							numbers[j - x] = true;
						}
					}
				}
			}

			for (int i = 0; i <= y - x; i++) {
				if (!numbers[i]) {
					System.out.println(i + x);
				}
			}

		}
		s.close();
	}

}
